import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Auther: yaozun
 * @Date: 2018/4/17 0017 10:29
 * @Description:
 */

@WebServlet("/ServletTest")//对应浏览器请求的路径（或者在web.xml中配置）
public class ServletTest extends HttpServlet{
    private String message;

    @Override
    public void init() throws ServletException {
        message = "Hello world, this message is from servlet!";
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//设置响应内容类型
        resp.setContentType("text/html");
//设置逻辑实现
        PrintWriter out = resp.getWriter();
        out.println("<h3>" + message + "</h3>");
    }
    @Override
    public void destroy() {
        super.destroy();
    }
}
